package controller;

import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@WebServlet("/TestServlet")
public class ABCListenerServlet extends HttpServlet {
	public ABCListenerServlet() {
		System.out.println("执行TestServlet的构造方法！");
	}
	public void init(ServletConfig config) throws ServletException {
		System.out.println("执行TestServlet的init方法！");
	}
	public void destroy() {
		System.out.println("执行TestServlet的destroy方法！");
	}
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ServletContext sc= request.getServletContext();
		sc.setAttribute("scName", "scValue1");//绑定属性
		sc.setAttribute("scName", "scValue2");//修改属性
		sc.removeAttribute("scName");//删除属性		
		
		request.setAttribute("requestName", "requestValue1");
		request.setAttribute("requestName", "requestValue2");
		request.removeAttribute("requestName");
		
		HttpSession session = request.getSession();
		session.setMaxInactiveInterval(5);
		session.setAttribute("sessionName", "sessionValue1");
		session.setAttribute("sessionName", "sessionValue2");
		session.removeAttribute("sessionName");
		request.changeSessionId();
		session.invalidate();
	}
}
